package com.bcx.crm.java.proxy.jdkProxy3;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by ys on 2018/1/27.
 */
public class MyInvocationHandler implements InvocationHandler {
    private Object target;
    public MyInvocationHandler(Object target){
        this.target=target;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("执行代理方法的前置操作");
        Object result = method.invoke(target, args);  //此处要使用目标类，不能使用proxy代理类(报错，死循环)
        System.out.println("代理类："+this.getClass()+"执行了目标类："+target.getClass()+"的方法:"+method.getName()+"参数是："+args);
        System.out.println("执行代理方法的后置操作");
        return result;
    }
}
